package com.ss.android.article.base.feature.detail2.a.c;

import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.feature.detail.model.MixedAdsData;
import com.ss.android.article.base.feature.detail.model.PhoneAdsData;
import com.ss.android.article.base.feature.detail2.widget.ProgressTextView;
import com.ss.android.article.base.feature.detail2.widget.ProgressTextView.Status;
import com.ss.android.article.base.feature.detail2.widget.a.BaseDetailLayout;
import com.ss.android.article.base.feature.model.DownloadAppAd;
import com.ss.android.article.base.ui.EllipsisTextView;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.b.a.BaseAdsData;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.download.DownloadShortInfo;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.image.Image;
import com.ss.android.image.model.ImageInfo;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

public final class DetailAdGroupPicLayout extends BaseDetailLayout implements z {
    ProgressTextView a;
    com.ss.android.article.base.feature.detail2.a.b.a b;
    long c;
    String d;
    JSONObject e;
    private View f;
    private NightModeAsyncImageView g;
    private NightModeAsyncImageView h;
    private NightModeAsyncImageView j;
    private TextView k;
    private EllipsisTextView l;
    private TextView m;
    private ViewGroup n;
    private TextView o;
    private TextView p;
    private com.ss.android.article.base.feature.detail2.a.aa q;

    public DetailAdGroupPicLayout(Context arg1) {
        super(arg1);
    }

    public DetailAdGroupPicLayout(Context arg2, byte arg3) {
        super(arg2, (byte) 0);
    }

    private boolean a(List arg11) {
        int v3_1 = 0;
        boolean v3 = false;
        Object v0 = arg11.get(0);
        Object v1 = arg11.get(1);
        Object v2 = arg11.get(2);
        if ((((ImageInfo) v0).isValid()) && (((ImageInfo) v1).isValid()) && (((ImageInfo) v2).isValid())) {
            float v5 = this.getResources().getDimension(R.dimen.d6);
            float v6 = this.getResources().getDimension(R.dimen.d4);
            float v7 = this.getResources().getDimension(R.dimen.detail_ad_group_space);
            if (this.i == 0) {
                v3_1 = (this.getResources().getDisplayMetrics().widthPixels - (((int) v5)) * 2 - (((int) v6)) * 2 - (((int) v7)) * 2) / 3;
            } else if (this.i == 1) {
                v3_1 = (this.getResources().getDisplayMetrics().widthPixels - (((int) v5)) * 2 - (((int) v7)) * 2) / 3;
            }

            Image v0_1 = android.support.design.a.imageInfo2Image(((ImageInfo) v0));
            int v5_1 = ((int) ((((double) v0_1.height)) * (((double) (((int) v3_1)))) / (((double) v0_1.width))));
            this.g.setImage(v0_1);
            this.h.setImage(android.support.design.a.imageInfo2Image(((ImageInfo) v1)));
            this.j.setImage(android.support.design.a.imageInfo2Image(((ImageInfo) v2)));
            if ((((int) v3_1)) > 0 && v5_1 > 0) {
                ViewGroup.LayoutParams v0_2 = this.g.getLayoutParams();
                if (v0_2 != null) {
                    v0_2.width = ((int) v3_1);
                    v0_2.height = v5_1;
                    this.g.setLayoutParams(v0_2);
                }

                v0_2 = this.h.getLayoutParams();
                if (v0_2 != null) {
                    v0_2.width = ((int) v3_1);
                    v0_2.height = v5_1;
                    this.h.setLayoutParams(v0_2);
                }

                v0_2 = this.j.getLayoutParams();
                if (v0_2 == null) {
//                    goto label_56;
                } else {
                    v0_2.width = ((int) v3_1);
                    v0_2.height = v5_1;
                    this.j.setLayoutParams(v0_2);
                }
            }
//            label_56:
            v3 = true;
        }

        return v3;
    }

    public final void initView() {
        super.initView();
        if (this.i == 0) {
            this.setBackgroundResource(com.ss.android.article.browser.R.drawable.detail_ad_bg);
        } else if (this.i == 1) {
            this.setBackgroundResource(com.ss.android.article.browser.R.color.transparent);
        }

        this.g = this.findViewById(com.ss.android.article.browser.R.id.ad_pic_left);
        this.h = this.findViewById(com.ss.android.article.browser.R.id.ad_pic_mid);
        this.j = this.findViewById(com.ss.android.article.browser.R.id.ad_pic_right);
        this.k = this.findViewById(com.ss.android.article.browser.R.id.ad_source_tv_name);
        this.l = this.findViewById(com.ss.android.article.browser.R.id.ad_tv_title);
        this.a = this.findViewById(com.ss.android.article.browser.R.id.ad_tv_creative);
        this.m = this.findViewById(com.ss.android.article.browser.R.id.ad_label_info);
        this.f = this.findViewById(com.ss.android.article.browser.R.id.download_area);
    }

    public final void setAdData(BaseAdsData arg8) {
        int v0_2;
        final BaseAdsData v0_1;
        int v6 = 8;
        if (arg8 != null) {
            this.c = arg8.id;
            try {
                this.e = new JSONObject();
                this.e.put("log_extra", arg8.logExtra);
            } catch (JSONException v0) {
                v0.printStackTrace();
            }

            this.d = arg8.pkg;
            this.q = new com.ss.android.article.base.feature.detail2.a.aa(arg8);
            if ((arg8 instanceof DownloadAppAd)) {
                v0_1 = arg8;
                if (!((DownloadAppAd) v0_1).b()) {
                    v0_2 = 0;
                } else if (!this.a(((DownloadAppAd) v0_1).imageList)) {
                    v0_2 = 0;
                } else {
                    if (!android.support.design.a.isTextEmpty(((DownloadAppAd) v0_1).appAdTitle) && !android.support.design.a.isTextEmpty(((DownloadAppAd) v0_1).webUrl)) {
                        this.b = new com.ss.android.article.base.feature.detail2.a.b.a(this.getContext(), ((DownloadAppAd) v0_1));
                        if (!android.support.design.a.isTextEmpty(((DownloadAppAd) v0_1).appAdSourceLabel)) {
                            this.m.setText(((DownloadAppAd) v0_1).appAdSourceLabel);
                        }

                        this.a.setVisibility(VISIBLE);
                        ProgressTextView v4 = this.a;
                        String v1 = android.support.design.a.isTextEmpty(((DownloadAppAd) v0_1).btnTxt) ? this.getResources().getString(com.ss.android.article.browser.R.string.j2) : ((DownloadAppAd) v0_1).btnTxt;
                        v4.setText(((CharSequence) v1));
                        this.l.setText(((DownloadAppAd) v0_1).appAdTitle);
                        this.a.setOnClickListener(new d(this));
                        this.k.setText(((DownloadAppAd) v0_1).appName);
                        this.f.setVisibility(VISIBLE);
                        v0_2 = 1;
//                        goto label_25;
                    } else {
                        v0_2 = 0;
                    }
                }
            } else {
                if ((arg8 instanceof MixedAdsData)) {
                    v0_1 = arg8;
                    if (!((MixedAdsData) v0_1).isGroupImage()) {
                        v0_2 = 0;
//                        goto label_25;
                    } else if (!this.a(((MixedAdsData) v0_1).imageList)) {
                        v0_2 = 0;
//                        goto label_25;
                    } else if (!android.support.design.a.isTextEmpty(((MixedAdsData) v0_1).title) && !android.support.design.a.isTextEmpty(((MixedAdsData) v0_1).webUrl)) {
                        if (this.i == 0) {
                            this.l.setText(((MixedAdsData) v0_1).title);
                            if (!android.support.design.a.isTextEmpty(((MixedAdsData) v0_1).h)) {
                                this.m.setText(((MixedAdsData) v0_1).h);
                            }

                            this.f.setVisibility(GONE);
                        } else {
                            if (this.i != 1) {
//                                goto label_114;
                            } else {
                                this.l.setText(((MixedAdsData) v0_1).title);
                                this.f.setVisibility(GONE);
                                this.n = this.findViewById(com.ss.android.article.browser.R.id.video_mix_area);
                                this.n.setVisibility(VISIBLE);
                                this.o = this.findViewById(com.ss.android.article.browser.R.id.ad_label_info_mix);
                                this.p = this.findViewById(com.ss.android.article.browser.R.id.ad_source_tv_name_mix);
                                if (!android.support.design.a.isTextEmpty(((MixedAdsData) v0_1).h)) {
                                    this.o.setText(((MixedAdsData) v0_1).h);
                                }
                                this.p.setText(((MixedAdsData) v0_1).i);
                            }
                        }

                        label_114:
                        v0_2 = 1;
//                        goto label_25;
                    } else {
                        v0_2 = 0;
                    }
//                    goto label_25;
                } else if ((arg8 instanceof PhoneAdsData)) {
                    v0_1 = arg8;
                    if (!((PhoneAdsData) v0_1).isGroupImage()) {
                        v0_2 = 0;
//                        goto label_25;
                    } else if (!this.a(((PhoneAdsData) v0_1).imageList)) {
                        v0_2 = 0;
//                        goto label_25;
                    } else if (!android.support.design.a.isTextEmpty(((PhoneAdsData) v0_1).title) && !android.support.design.a.isTextEmpty(((PhoneAdsData) v0_1).webUrl) && !android.support.design.a.isTextEmpty(((PhoneAdsData) v0_1).sourceName)) {
                        this.f.setVisibility(VISIBLE);
                        if (!android.support.design.a.isTextEmpty(((PhoneAdsData) v0_1).h)) {
                            this.m.setText(((PhoneAdsData) v0_1).h);
                        }

                        this.k.setText(((PhoneAdsData) v0_1).sourceName);
                        this.l.setText(((PhoneAdsData) v0_1).title);
                        if ((TextUtils.isEmpty(((PhoneAdsData) v0_1).phoneNumber)) || (TextUtils.isEmpty(((PhoneAdsData) v0_1).buttonText))) {
                            this.a.setVisibility(GONE);
                        } else {
                            this.a.setText(((PhoneAdsData) v0_1).buttonText);
                            this.a.setOnClickListener(new View.OnClickListener() {
                                private final PhoneAdsData a = (PhoneAdsData) v0_1;


                                public final void onClick(View arg11) {
                                    MobAdClickCombiner.onAdEvent(
                                            DetailAdGroupPicLayout.this.getContext(),
                                            "detail_call",
                                            "click_call",
                                            DetailAdGroupPicLayout.this.c,
                                            0,
                                            DetailAdGroupPicLayout.this.e,
                                            1);
                                    MobAdClickCombiner.onAdEvent(DetailAdGroupPicLayout.this.getContext(),
                                            "detail_call",
                                            "click", DetailAdGroupPicLayout.this.c,
                                            0,
                                            DetailAdGroupPicLayout.this.e, 1);
                                    ToolUtils.e(DetailAdGroupPicLayout.this.getContext(), this.a.phoneNumber);
                                }
                            });
                        }

                        v0_2 = 1;
                    } else {
                        v0_2 = 0;
                    }
                } else {
                    v0_2 = 0;
                }
            }
            if (v0_2 == 0) {
                this.setVisibility(GONE);
                arg8.K = false;
            } else {
                arg8.K = true;
                this.setOnClickListener(new com.ss.android.article.base.feature.detail2.a.c.c(this, arg8));
            }
        }
    }

    public final void a(DownloadShortInfo arg5) {
        if (arg5 == null) {
            this.a.setStatus(Status.IDLE);
        } else {
            float v0 = (((float) arg5.d)) / (((float) arg5.c));
            switch (arg5.b) {
                case 1:
                case 2: {
                    this.a.setStatus(Status.DOWNLOADING);
                    this.a.setProgress(v0);
                    return;
                }
                case 4: {
                    this.a.setStatus(Status.PAUSING);
                    this.a.setProgress(v0);
                    return;
                }
                case 8: {
                    if (ToolUtils.isAppInstalled(this.getContext(), this.d)) {
                        this.a.setStatus(Status.FINISH_OPEN);
                        this.q.a("detail_download_ad");
                    } else {
                        this.a.setStatus(Status.FINISH_INSTALL);
                    }
                    return;
                }
                case 16: {
                    this.a.setStatus(Status.FAILURE);
                    return;
                }
            }

            Logger.d("DetailAdGroupPicLayout", "download short info error!");
            return;
        }
    }

    public final void a(DownloadShortInfo arg10, int arg11, long arg12, long arg14) {
        this.post(new b(this, arg14, arg12, arg11, arg10));
    }

    public final void adaptNightMode(boolean arg6) {
        int v2 = R.color.update_comment_more_text_selector;
        int v1 = R.color.ssxinzi1;
        Resources v3 = this.getResources();
        TextView v4 = this.k;
        int v0 = this.i == 0 ? v1 : R.color.ssxinzi2;
        v4.setTextColor(v3.getColorStateList(v0));
        this.l.setTextColor(v3.getColorStateList(v1));
        TextView v1_1 = this.m;
        v0 = this.i == 0 ? R.color.ssxinzi12 : v2;
        v1_1.setTextColor(v3.getColorStateList(v0));
        v0 = this.i == 0 ? R.drawable.detail_ad_bg : R.drawable.e;
        this.setBackgroundResource(v0);
        this.a.b();
        this.g.adaptNightMode(arg6);
        this.h.adaptNightMode(arg6);
        this.j.adaptNightMode(arg6);
        if (this.o != null) {
            this.o.setTextColor(v3.getColorStateList(v2));
        }

        if (this.p != null) {
            this.p.setTextColor(v3.getColorStateList(com.ss.android.article.browser.R.color.ssxinzi3));
        }
    }

    public final void b() {
        if (this.b != null) {
            this.b.d();
        }
    }

    public final int getLayoutRes() {
        int v0 = this.i == 0 ? R.layout.new_detail_ad_group_pic : R.layout.detail_video_ad_group_pic;
        return v0;
    }

    protected final void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (this.b != null) {
            this.b.a(((z) this));
        }
    }

    protected final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.b != null) {
            this.b.a();
        }
    }

    public final void setAdImage(Image arg1) {
    }
}

